<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>
    
    document.onclick = function(){
        const a1 = alert({
            text:"提示信息"
        })
        const a2 = alert({
            text:"提示信息"
        })
        console.log(a1 === a2);
    }

    // 单例模式的提示框
    function alert(ops){
        if(!alert.obj){
            alert.obj = {};
            alert.obj.ele = document.createElement("dialog");
            document.body.appendChild(alert.obj.ele);
        }
        alert.obj.ele.innerHTML = ops.text || "默认提示";
        alert.obj.ele.style.display = "block";

        if(ops.closeType === "click"){
            alert.obj.ele.onclick= function(){
                alert.obj.ele.style.display = "none";
                ops.close && ops.close();
            }
        }else{
            setTimeout(()=>{
                alert.obj.ele.style.display = "none";
                ops.close && ops.close();
            },2000)
        }
        return alert.obj;
    }
</script>
</html>